<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String t = (String) request.getSession().getAttribute("t");
if (MyFun.isEmpty(t)) {
	out.print("{\"MSG\":\"令牌错误\",\"CODE\":0}");
	return;
}
%>
<%@page import="hyl.core.info.Content"%>
<%@page import="hyl.ext.web.ms.*,hyl.base.cache2.*"%>
<%@page import="com.servlet.My,com.dao.SqlOfUser"%>
<%@page import="hyl.core.MyFun,hyl.core.db.MyDB"%>
<%@page import="hyl.core.net.MyHttp,hyl.ext.base.MySession"%>
<%@page import="java.net.HttpURLConnection"%>
<%@page import="java.io.PrintWriter,java.util.Map"%>
<%@page import="com.control.SystemControl"%>
<%
Content ct = new Content();
String name = request.getParameter("name");
String pass = request.getParameter("pass");

TMsA ma = TMsA.getInstance();
ExToken et = ma.getExToken(t);
if (et == null) {
	ct.setCode(0, "令牌已过期,请在关闭后重新登录!!");
} else {
	//先检查app_user中该用户A是否存在 如果存在 说明已经注册绑定		b_a.jsp
	Map<String, Object> mp = SqlOfUser.login(name,pass);
	if (mp == null || mp.isEmpty()) {
		//用户不存在,跳转到注册页面		
		// MyFun.print(name);
		if (et.exec() == 0) {
			ct.setCode(0, name + "你已经重试三次");
			ma.removeExToken(t);
		} else {
			ct.setCode(1, name + "账号或密码错误");
		}
	} else { //如果用户A name 存在  			 
		
		//如果密码正确 绑定成功	
			MySession se = My.getSession(request, response);
			SystemControl.checkLogin(se, name, pass);
			//MyFun.print("----a--session----", se.toJsonString());
			MyDB db = My.getDB1();
			String openid = MyFun.getUUID();
			String appidb = (String) et._附件.get("appb");
			Object useridb = et._附件.get("uidb");
			Object unameb = et._附件.get("unameb");
			Object sidb = et._附件.get("sidb");
			Object ipb = et._附件.get("ipb");
			BInfo bi = ma.getBInfo(appidb);
			String sql = "insert into app_user (openid,appB,uidA,unamea,uidB,unameb,sidA,sidB,ipB) values(?,?,?,?,?,?,?,?,?)";
			Object[] params = { openid, appidb, se.getUserId(), se.getUname(), useridb, unameb, se.getTokenId(), sidb,
					ipb };
			//MyFun.print(params);
			db.executeUpdate(sql, params);
			ct.setCode(2, "绑定成功");
			ma.removeExToken(t);
		
	}
}

request.getSession().removeAttribute("t");

out.print(ct.toJsonString());
//System.out.println(My._rd.get("hahaha", "appid"));
%>